//
//
//
#include "portocolMarket.h"
#include <utf.h>

_LIT8(KInterfaceNo, "interfaceno");

_LIT8(KReqMarketURL, "http://58.246.187.214/client.php?ac=market");
_LIT(KReqMarketData, "uid=%s&rand=%s");
_LIT(KReqInfoNone, "\"\"");

CRocketRequestMarket::CRocketRequestMarket(MNetworkEventObervser* aObserver) : CRocketRequest(aObserver)
	{
		iUrl.Copy(KReqMarketURL());
		iNumber = CMSGMARKET;
	}

CRocketRequestMarket::~CRocketRequestMarket()
	{
		
	}

void CRocketRequestMarket::SetInfo(const TDesC8& aUid, const TDesC8& aRand)
{
	iUid.Zero();
	iRand.Zero();
	
	iUid.Copy(aUid);
	iRand.Copy(aRand);
}

TBool CRocketRequestMarket::Encode()
{
	TBuf<512> buf;
	buf.Format(KReqMarketData(),
				iUid.PtrZ(),
				iRand.PtrZ());
	
	TBuf8<1024> buf8;
	CnvUtfConverter::ConvertFromUnicodeToUtf8(buf8,buf);
	this->iData = buf8.Alloc();
	return ETrue;
}

CRocketResponseMarket::CRocketResponseMarket()
	{
	
	}

CRocketResponseMarket::~CRocketResponseMarket()
	{
	
	}

void CRocketResponseMarket::OnEndElementL(const Xml::RTagInfo &aElement, 
										TInt aErrorCode)
{
	
}

// XML tags
//?????
_LIT8(KMarketTag, "Market");
_LIT8(KRetTag, "ret");

void CRocketResponseMarket::OnStartElementL(const Xml::RTagInfo& aElement,
						const Xml::RAttributeArray& aAttributes,
						TInt aErrorCode)
{
	if(aElement.LocalName().DesC() == KInterfaceNo)
	{
		
	}
	else if(aElement.LocalName().DesC() == KMarketTag)
	{
		for(TInt nIndex = 0; nIndex < aAttributes.Count(); nIndex ++)
		{
			//Xml::RAttribute attr = aAttributes.At(nIndex);
			if(0 == aAttributes[nIndex].Attribute().LocalName().DesC().Compare(KRetTag))
			{
				TLex8 aLex(aAttributes[nIndex].Value().DesC());
				aLex.Val(iReturnNumber);
			}
		}
	}
}
